package com.atguigu.rabbitmq.simple;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author 杨林
 * @create 2022-10-06 10:41 星期四
 * description:简单模式的生产者
 */
public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置主机地址
        factory.setHost("192.168.10.128");
        //连接端口  默认端口5672
        factory.setPort(5672);
        //设置虚拟主机名称
        factory.setVirtualHost("/");
        //设置连接用户名
        factory.setUsername("admin");
        //连接密码
        factory.setPassword("admin");
        //创建连接
        Connection connection = factory.newConnection();
        //创建频道
        Channel channel = connection.createChannel();
        //System.out.println(channel);
        //声明队列
        channel.queueDeclare("simple_queue", true,false,true,null);
        String message = "hello rabbitmq";
        channel.basicPublish("","simple_queue", null,message.getBytes());

        //关闭资源
        channel.close();
        connection.close();
    }
}
